<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="res/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=updateCrushStatus0",
		"dataType":"json",
		"success":function(){
		}
	});
	
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=updateChemicalStatus0",
		"dataType":"json",
		"success":function(){
		}
	});
	
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=updateDryingStatus0",
		"dataType":"json",
		"success":function(){
		}
	});
	
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=updateCuttingStatus0",
		"dataType":"json",
		"success":function(){
		}
	});
	
	
	$("#p4start").click(function(){
		$.ajax({
			"url":"/management-mod/management.do",
			"type":"post",
			"data":"method=CuttingStartClick",
			"dataType":"json",
			"success":function(){
			}
		});
	});
	$("#p4start").click(function(){
		$.ajax({
			"url":"/management-mod/management.do",
			"type":"post",
			"data":"method=selectCuttingStatus",
			"dataType":"json",
			"success":function(returnData){
				if(returnData==0){
					p4status1();
				}else{
					alert("딴데서 실행중임");
				}
			}
		});
	});
	$("#p3start").click(function(){
		$.ajax({
			"url":"/management-mod/management.do",
			"type":"post",
			"data":"method=DryingStartClick",
			"dataType":"json",
			"success":function(){
			}
		});
	});
	$("#p3start").click(function(){
		$.ajax({
			"url":"/management-mod/management.do",
			"type":"post",
			"data":"method=selectDryingStatus",
			"dataType":"json",
			"success":function(returnData){
				if(returnData==0){
					p3status1();
				}else{
					alert("딴데서 실행중임");
				}
			}
		});
	});
	$("#p1start").click(function(){
		$.ajax({
			"url":"/management-mod/management.do",
			"type":"post",
			"data":"method=CrushStartClick",
			"dataType":"json",
			"success":function(){
			}
		});
	});
	$("#p1start").click(function(){
		$.ajax({
			"url":"/management-mod/management.do",
			"type":"post",
			"data":"method=selectCrushStatus",
			"dataType":"json",
			"success":function(returnData){
				if(returnData==0){
					p1status1();
				}else{
					alert("딴데서 실행중임");
				}
			}
		});
	});
	$("#p2start").click(function(){
		$.ajax({
			"url":"/management-mod/management.do",
			"type":"post",
			"data":"method=ChemicalStartClick",
			"dataType":"json",
			"success":function(){
			}
		});
	});
	$("#p2start").click(function(){
		$.ajax({
			"url":"/management-mod/management.do",
			"type":"post",
			"data":"method=selectChemicalStatus",
			"dataType":"json",
			"success":function(returnData){
				if(returnData==0){
					p2status1();
				}else{
					alert("딴데서 실행중임");
				}
			}
		});
	});
	$("#start").click(function(){
		$.ajax({
			"url":"management.do",
			"type":"post",
			"data":{"method":"updateTreeStop0"},
			"dataType":"json",
			"success":function(){
			}
		});
	});
	$("#start").click(function(){
		$.ajax({
			"url":"management.do",
			"type":"post",
			"data":{"method":"Tree"},
			"dataType":"json",
			"success":function(returnData){
					var div = document.getElementById("div");
					var div2 = document.createElement("div");
					div2.innerHTML= "<h3>Generator</h3><br>업체 : " + returnData.tto.enterPrise +
					", 나무 종류 : " + returnData.tto.treeType +
					", 나무 등급 : " + returnData.tto.treeGrade +
					", 나무 수량 : " + returnData.tto.treeCount +
					", 주문일 : " + returnData.tto.orderDate;
					div.appendChild(div2);
					if(returnData.stop==0){
						start();
						}else{
							
						}
			}
		});
	});
	$("#stop").click(function(){
		$.ajax({
			"url":"management.do",
			"type":"post",
			"data":{"method":"updateTreeStop1"},
			"dataType":"json",
			"success":function(){
			}
		});
	});
	$("#p1stop").click(function(){
		$.ajax({
			"url":"management.do",
			"type":"post",
			"data":{"method":"CrushStopClick"},
			"dataType":"json",
			"success":function(){
			}
		});
	});
	$("#p2stop").click(function(){
		$.ajax({
			"url":"management.do",
			"type":"post",
			"data":{"method":"ChemicalStopClick"},
			"dataType":"json",
			"success":function(){
			}
		});
	});
	$("#p3stop").click(function(){
		$.ajax({
			"url":"management.do",
			"type":"post",
			"data":{"method":"DryingStopClick"},
			"dataType":"json",
			"success":function(){
			}
		});
	});
	$("#p4stop").click(function(){
		$.ajax({
			"url":"management.do",
			"type":"post",
			"data":{"method":"CuttingStopClick"},
			"dataType":"json",
			"success":function(){
			}
		});
	});
	
	
	
});

function p1(){
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=Crush",
		"dataType":"json",
		"success":function(returnData){
				var div = document.getElementById("div");
				var div2 = document.createElement("div");
				if(returnData!=null){
					div2.innerHTML= "<h3>P1공정</h3><br>업체 : " + returnData.cto.enterPrise +
					", 파쇄 후 나무 무게 : " + returnData.cto.treeWeight +
					", 제조공정일 : " + returnData.cto.productDate +
					"<br> 처리시간 : "+returnData.time;
				}else if(returnData.equals(null)){
					div2.innerHTML="p1 대기중";
				}
				div.appendChild(div2);
				if(returnData.stop==0){
					p1();
					}else{
						
					}
		}
	});
}
function p1status1(){
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=updateCrushStatus1",
		"dataType":"json",
		"success":function(){
			p1();
		}
	});
}

function p2(){
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=Chemical",
		"dataType":"json",
		"success":function(returnData){
				var div = document.getElementById("div");
				var div2 = document.createElement("div");
				if(returnData!=null){
					div2.innerHTML= "<h3>P2공정</h3><br>업체 : " + returnData.cmto.enterPrise +
					", 화학처리 후 펄프 무게 : " + returnData.cmto.pulpWeight +
					", 제조공정일 : " + returnData.cmto.productDate +
					"<br> 처리시간 : "+returnData.time;
				}else if(returnData==null){
					div2.innerHTML="p2 대기중";
				}
				div.appendChild(div2);
				if(returnData.stop==0){
					p2();
					}else{
						
					}
		}
	});
}
function p2status1(){
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=updateChemicalStatus1",
		"dataType":"json",
		"success":function(){
			p2();
		}
	});
}

function p3(){
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=Drying",
		"dataType":"json",
		"success":function(returnData){
				var div = document.getElementById("div");
				var div2 = document.createElement("div");
				if(returnData!=null){
					div2.innerHTML= "<h3>P3공정</h3><br>업체 : " + returnData.dto.enterPrise +
					", 건조 후 종이 무게 : " + returnData.dto.paperWeight +
					", 제조공정일 : " + returnData.dto.productDate +
					"<br> 처리시간 : "+returnData.time;
				}else{
					div2.innerHTML="p3 대기중";
				}
				div.appendChild(div2);
				if(returnData.stop==0){
					p3();
					}else{
						
					}
		}
	});
}
function p3status1(){
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=updateDryingStatus1",
		"dataType":"json",
		"success":function(){
			p3();
		}
	});
}
function p4(){
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=Cutting",
		"dataType":"json",
		"success":function(returnData){
				var div = document.getElementById("div");
				var div2 = document.createElement("div");
				if(returnData!=null){
					div2.innerHTML= "<h3>P4공정</h3><br>업체 : " + returnData.cuto.enterPrise +
					", 완성된 종이 수량 : " + returnData.cuto.paperCount +
					", 제조공정일 : " + returnData.cuto.productDate +
					"<br> 처리시간 : "+returnData.time;
				}else{
					div2.innerHTML="p4 대기중";
				}
				div.appendChild(div2);
				if(returnData.stop==0){
					p4();
					}else{
						
					}
		}
	});
}
function p4status1(){
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=updateCuttingStatus1",
		"dataType":"json",
		"success":function(){
			p4();
		}
	});
}
function start(){
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=Tree",
		"dataType":"json",
		"success":function(returnData){
				var div = document.getElementById("div");
				var div2 = document.createElement("div");
				div2.innerHTML= "<h3>Generator</h3><br>업체 : " + returnData.tto.enterPrise +
				", 나무 종류 : " + returnData.tto.treeType +
				", 나무 등급 : " + returnData.tto.treeGrade +
				", 나무 수량 : " + returnData.tto.treeCount +
				", 주문일 : " + returnData.tto.orderDate;
				div.appendChild(div2);
				if(returnData.stop==0){
					start();
					}else{
						
					}
		}
	});
}


$(window).unload(function(){
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=updateCrushStatus0",
		"dataType":"json",
		"success":function(){
		}
	});
	
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=updateChemicalStatus0",
		"dataType":"json",
		"success":function(){
		}
	});
	
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=updateDryingStatus0",
		"dataType":"json",
		"success":function(){
		}
	});
	
	$.ajax({
		"url":"/management-mod/management.do",
		"type":"post",
		"data":"method=updateCuttingStatus0",
		"dataType":"json",
		"success":function(){
		}
	});
	
});



</script>
<title>Insert title here</title>
</head>
<body>
<table>
<tr>
	<td>
	(트리가동)
	</td>
	<td>
<button id="start">Tree start</button>
	</td>
	<td>
<button id="stop">Tree stop</button>
	</td>
</tr>
<tr></tr>
<tr>
	<td>
<button id="p1start">p1 start</button>
	</td>
	<td>
<button id="p2start">p2 start</button>	
	</td>
	<td>
<button id="p3start">p3 start</button>	
	</td>
	<td>
<button id="p4start">p4 start</button>	
	</td>
</tr>
<tr>
	<td>
<button id="p1stop">p1 stop</button>
	</td>
	<td>
<button id="p2stop">p2 stop</button>
	</td>
	<td>
<button id="p3stop">p3 stop</button>	
	</td>
	<td>
<button id="p4stop">p4 stop</button>
	</td>
</tr>
</table>
<div id="div"></div>
</body>
</html>